package org.example.myleet.p815;

import org.example.myleet.Utils.Assert;
import org.example.myleet.Utils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        Assert.isTrue(0 == solution.numBusesToDestination(parseRoutes("[[1,2,7],[3,6,7]]"), 3, 6));
        Assert.isTrue(2 == solution.numBusesToDestination(parseRoutes("[[1,2,7],[3,6,7]]"), 1, 6));
        Assert.isTrue(-1 == solution.numBusesToDestination(parseRoutes("[[7,12],[4,5,15],[6],[15,19],[9,12,13]]"), 15, 12));
        Assert.isTrue(2 == solution.numBusesToDestination(parseRoutes("[[7,12],[4,5,15],[6],[15,19],[9,12,13]]"), 7, 13));
        Assert.isTrue(5 == solution.numBusesToDestination(parseRoutes("[[7,12],[4,5,15],[6],[15,19],[9,12,13],[13,14],[15,16],[14,15]]"), 7, 16));
        Assert.isTrue(-1 == solution.numBusesToDestination(parseRoutes("[[7,12],[4,5,15],[6],[15,19],[9,12,13],[13,14],[15,16],[14,15]]"), 8, 16));
    }

    private static int[][] parseRoutes(String input) {
        List<List<Integer>> parsedRoutes = JsonUtils.parse(input, List.class);
        List<int[]> result1 = new ArrayList<>(parsedRoutes.size());
        for (List<Integer> list : parsedRoutes) {
            int[] route = new int[list.size()];
            int j = 0;
            for (Integer integer : list) {
                route[j++] = integer;
            }
            result1.add(route);
        }
        int[][] result = new int[parsedRoutes.size()][0];
        int i = 0;
        for (int[] route : result1) {
            result[i++] = route;
        }
        return result;
    }
}
